package com.stox.shared.event;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

@Component
@Lazy(false)
public class EventPublisher implements InitializingBean{

	private static ApplicationContext staticApplicationContext;
	
	@Autowired
	private ApplicationContext applicationContext;
	
	@Override
	public void afterPropertiesSet() throws Exception {
		staticApplicationContext = applicationContext;
	}
	
	public static <T extends ApplicationEvent> void publishEvent(T event){
		staticApplicationContext.publishEvent(event);
	}
}
